From 1723fa86a51e42f025aafb192afe215e7176e156 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 17 Feb 2025 09:14:05 +0100 Subject: [PATCH] detect the need to sign the terms of service during login web flow v2 should avoid being blocked by terms_of_service blocking WebDAV access Signed-off-by: Matthieu Gallien Signed-off-by: Jyrki Gadinger --- src/gui/connectionvalidator.cpp | 2 +- src/gui/owncloudsetupwizard.cpp | 50 ++++++++++++++++---- src/gui/owncloudsetupwizard.h | 7 ++- src/gui/wizard/owncloudadvancedsetuppage.cpp | 10 ++++ src/gui/wizard/owncloudadvancedsetuppage.h | 2 + 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 31467ec3f..61ba6ee44 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -390,8 +390,8 @@ void TermsOfServiceChecker::slotServerTermsOfServiceRecieved(const QJsonDocument if (reply.object().contains("ocs")) { const auto needToSign = !reply.object().value("ocs").toObject().value("data").toObject().value("hasSigned").toBool(false); if (needToSign != _needToSign) { - qCInfo(lcConnectionValidator) << "_needToSign" << (_needToSign ? "need to sign" : "no need to sign"); _needToSign = needToSign; + qCInfo(lcConnectionValidator) << "_needToSign" << (_needToSign ? "need to sign" : "no need to sign"); emit needToSignChanged(); } } else if (_needToSign) { diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 66282a067..8f10fc52f 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -13,13 +13,6 @@ * for more details. */ -#include -#include -#include -#include -#include -#include - #include "accessmanager.h" #include "account.h" #include "accountmanager.h" @@ -35,11 +28,23 @@ #include "sslerrordialog.h" #include "wizard/owncloudwizard.h" #include "wizard/owncloudwizardcommon.h" +#include "connectionvalidator.h" #include "creds/credentialsfactory.h" #include "creds/abstractcredentials.h" #include "creds/dummycredentials.h" +#ifdef BUILD_FILE_PROVIDER_MODULE +#include "gui/macOS/fileprovider.h" +#endif + +#include +#include +#include +#include +#include +#include + namespace OCC { OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent) @@ -377,7 +382,14 @@ void OwncloudSetupWizard::testOwnCloudConnect() job->setFollowRedirects(false); job->setProperties(QList() << "getlastmodified"); connect(job, &PropfindJob::result, _ocWizard, &OwncloudWizard::successfulStep); - connect(job, &PropfindJob::finishedWithError, this, &OwncloudSetupWizard::slotAuthError); + connect(job, &PropfindJob::finishedWithError, this, [this] (QNetworkReply *reply) { + if (reply && reply->error() == QNetworkReply::ContentAccessDenied) { + testTermsOfService(); + } else { + slotAuthError(); + } + }); + job->start(); } @@ -416,6 +428,9 @@ void OwncloudSetupWizard::slotAuthError() // A 404 is actually a success: we were authorized to know that the folder does // not exist. It will be created later... + } else if (reply->error() == QNetworkReply::ContentAccessDenied) { + testTermsOfService(); + return; } else if (reply->error() == QNetworkReply::ContentNotFoundError) { _ocWizard->successfulStep(); return; @@ -473,6 +488,14 @@ bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply *reply) return true; } +void OwncloudSetupWizard::testTermsOfService() +{ + _termsOfServiceChecker = new TermsOfServiceChecker{_ocWizard->account(), this}; + + connect(_termsOfServiceChecker, &TermsOfServiceChecker::done, this, &OwncloudSetupWizard::termsOfServiceChecked); + _termsOfServiceChecker->start(); +} + void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString &localFolder, const QString &remoteFolder) { qCInfo(lcWizard) << "Setup local sync folder for new oC connection " << localFolder; @@ -726,6 +749,17 @@ void OwncloudSetupWizard::slotSkipFolderConfiguration() emit ownCloudWizardDone(QDialog::Accepted); } +void OwncloudSetupWizard::termsOfServiceChecked() +{ + if (_termsOfServiceChecker && _termsOfServiceChecker->needToSign()) { + QDesktopServices::openUrl(_ocWizard->account()->url()); + } else { + _ocWizard->successfulStep(); + delete _termsOfServiceChecker; + _termsOfServiceChecker = nullptr; + } +} + AccountState *OwncloudSetupWizard::applyAccountChanges() { AccountPtr newAccount = _ocWizard->account(); diff --git a/src/gui/owncloudsetupwizard.h b/src/gui/owncloudsetupwizard.h index d7288ee6c..fab85d9bb 100644 --- a/src/gui/owncloudsetupwizard.h +++ b/src/gui/owncloudsetupwizard.h @@ -30,6 +30,7 @@ namespace OCC { class AccountState; +class TermsOfServiceChecker; class OwncloudWizard; @@ -69,6 +70,8 @@ private slots: void slotAssistantFinished(int); void slotSkipFolderConfiguration(); + void termsOfServiceChecked(); + private: explicit OwncloudSetupWizard(QObject *parent = nullptr); ~OwncloudSetupWizard() override; @@ -79,8 +82,10 @@ private: bool ensureStartFromScratch(const QString &localFolder); AccountState *applyAccountChanges(); bool checkDowngradeAdvised(QNetworkReply *reply); + void testTermsOfService(); - OwncloudWizard *_ocWizard; + TermsOfServiceChecker *_termsOfServiceChecker = nullptr; + OwncloudWizard *_ocWizard = nullptr; QString _initLocalFolder; QString _remoteFolder; }; diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index bb51e4474..872f53f7f 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -176,6 +176,7 @@ void OwncloudAdvancedSetupPage::initializePage() quotaJob->setProperties(QList() << "http://owncloud.org/ns:size"); connect(quotaJob, &PropfindJob::result, this, &OwncloudAdvancedSetupPage::slotQuotaRetrieved); + connect(quotaJob, &PropfindJob::finishedWithError, this, &OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError); quotaJob->start(); @@ -547,6 +548,15 @@ void OwncloudAdvancedSetupPage::slotQuotaRetrieved(const QVariantMap &result) updateStatus(); } +void OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError(QNetworkReply *reply) +{ + Q_UNUSED(reply) + _rSize = -1; + _ui.lSyncEverythingSizeLabel->setText({}); + + updateStatus(); +} + qint64 OwncloudAdvancedSetupPage::availableLocalSpace() const { QString localDir = localFolder(); diff --git a/src/gui/wizard/owncloudadvancedsetuppage.h b/src/gui/wizard/owncloudadvancedsetuppage.h index 2c0f23bb4..d01ebe4d9 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.h +++ b/src/gui/wizard/owncloudadvancedsetuppage.h @@ -23,6 +23,7 @@ #include "elidedlabel.h" class QProgressIndicator; +class QNetworkReply; namespace OCC { @@ -63,6 +64,7 @@ private slots: void slotSelectiveSyncClicked(); void slotVirtualFileSyncClicked(); void slotQuotaRetrieved(const QVariantMap &result); + void slotQuotaRetrievedWithError(QNetworkReply *reply); private: void setRadioChecked(QRadioButton *radio); -- 2.30.2